package com.cictec.middleware.core.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cictec.middleware.core.entity.SystemDataDict;
import com.cictec.middleware.core.entity.SystemParam;
import com.cictec.middleware.core.mapper.SystemDataDictMapper;
import com.cictec.middleware.core.mapper.SystemParamMapper;

/**
 * 数据字典服务
 * 
 * @author ql
 *
 */
@Service
public class SystemDataDictService {

	public static Logger logger = LoggerFactory.getLogger(SystemDataDictService.class);

	@Autowired
	private SystemDataDictMapper systemDataDictMapper;
	@Autowired
	private SystemParamMapper systemParamMapper;

	/**
	 * 根据 字典编码，数据类型 获取数据类型
	 * 
	 * @param code
	 *            字典编码
	 * @param value
	 *            字典类型value
	 * @return
	 */
	public SystemDataDict selecDataDictate(String code, String value) {

		SystemDataDict tmp = new SystemDataDict();
		tmp.setCode(code);
		tmp.setValue(value);
		return systemDataDictMapper.selectOne(tmp);
	}

	/**
	 * 根据字典编码，获取所有该父编码的类型
	 * 
	 * @param code
	 * @return
	 */
	public List<SystemDataDict> selecDataDictate(String code) {
		SystemDataDict tmp = new SystemDataDict();
		tmp.setCode(code);

		return systemDataDictMapper.select(tmp);
	}

	/**
	 * 获取系统参数
	 * @param code
	 * @return
	 */
	public SystemParam selectSystemParamByCode(String code){
		SystemParam tmp = new SystemParam();
		tmp.setSpCode(code);
		List<SystemParam> list = systemParamMapper.select(tmp);
		if(list.size() > 0){
			return list.get(0);
		}else{
			// 定义默认值的地方
			if(code.equals("sp_bus_trip"))tmp.setSpValue("1");
		}
		
		return tmp;
	}
	
}
